<meta charset="utf-8">

{block name='script'}

<!-- <link href="__ROOT__/static/bootcss/bootstrap.min.css" rel="stylesheet"> -->

<script type="text/javascript" src="__ROOT__/static/plugs/jquery/jquery.min.js"></script>
<script type="text/javascript" src="__ROOT__/static/plugs/layui/layui.all.js"></script>
<link rel="stylesheet" type="text/css" href="__ROOT__/static/plugs/layui/css/layui.css" />
<link rel="stylesheet" href="__ROOT__/static/theme/css/console.css?at=1129">
<!--
<link rel="stylesheet" type="text/css" href="__ROOT__/static/plugs/Color/css/iColor-min.css" />
<script type="text/javascript" src="__ROOT__/static/plugs/Color/js/iColor-min.js"></script>
<script type="text/javascript" src="__ROOT__/static/plugs/Color/demo/demo.js"></script>
-->
<script src='__ROOT__/static/plugs/calendar/js/jquery.form.min.js'></script>
{/block}

{block name="content"}
<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
<div class="layui-card-body padding-left-40">

        <div class="layui-form-item">
            <label class="layui-form-label label-required">便签颜色</label>
            <div class="layui-input-block">
				<div id="mycolor"></div>
                <input name="color" id="color" class="layui-input" type="hidden" value="" size="6" />
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label label-required">日程内容</label>
            <div class="layui-input-block">
				<input name="event" id="event" value='{$vo.title|default=""}' required placeholder="请输入日程内容" class="layui-input">
            </div>
        </div>
		
        <div class="layui-form-item">
            <label class="layui-form-label label-required">开始时间</label>
            <div class="layui-input-block">
				<input name="startdate" id="startdate" data-date-input="date" value='{$date|default=""}' required placeholder="" class="layui-input" readonly>
            </div>		
			
        </div>


        <div class="layui-form-item" id="p_endtime" {$display}>
            <label class="layui-form-label label-required" >结束时间</label>
            <div class="layui-input-block">
				<input name="enddate" id="enddate" data-date-input="date" value='{$enddate|default=""}' required placeholder="" class="layui-input" readonly>
            </div>

			
        </div>	
		
		
        <div class="layui-form-item">
            <label class="layui-form-label ">日程分享</label>
            <div class="layui-input-block">
				<div id="sharer" class="xm-select-demo"></div>

            </div>
        </div>
		
		
        <div class="layui-form-item">
            <label class="layui-form-label label-required">全天</label>
            <div class="layui-input-block">

				<label class="think-checkbox layui-unselect"><input type="checkbox" name="isend" id="isend"  value="1" lay-filter="isend" lay-ignore="" onclick="checkbox_end();" {$chk}>是
				</label>
            </div>
        </div>	

	
	
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" type='submit' id="submit" lay-submit="" lay-filter="demo1" >保存数据</button>
				<button class="layui-btn layui-btn-danger" onclick="hsitoryBack()" type="button">关闭</button>
			</div>	
		</div>	

</div>
</form>
				      

		<script src="__ROOT__/static/plugs/select/xm-select.js"></script>
		<script>
		var sharer = xmSelect.render({
			el: '#sharer', 
			name: 'sharer',
			toolbar: {
				//show: true,
				//list: [ 'ALL', 'CLEAR', 'REVERSE' ]
			},
			direction: 'down',
			radio: false,
			filterable: true,
			paging: true,
			pageSize: 10,	
			on: function(data){
				//arr:  当前多选已选中的数据
				var arr = data.arr;
				
				//change, 此次选择变化的数据,数组
				var change = data.change;
				//onsole.log(arr);
				//isAdd, 此次操作是新增还是删除
				var isAdd = data.isAdd;
				
				//可以return一个数组, 代表想选中的数据
				//return []
			},
			
			data: [
				{$str}
			]
			
			
		});
		
		
		

	//window.form.render();
	
	function hsitoryBack(){
		//alert('11');
		layer.closeAll();
		parent.location.reload();
		return false;
		
		layer.confirm('确认关闭？', {
			btn: ['确定','取消'] //按钮
		}, function(){
			parent.location.reload();
		}, function(){
		
		});
		
		/*
		$.msg.confirm('确定要关闭吗？', function (index) {
			layer.closeAll('iframe');
			history.back(), $.msg.close(index);
		});*/
	};
	
	
function checkbox_end()
{
	var str=document.getElementsByName("isend");
	var objarray=str.length;
	var chestr="";
	for (i=0;i<objarray;i++)
	{
	  if(str[i].checked == true)
	  {
	    chestr =document.getElementById("p_endtime").style.display;
	  }
	}
	//console.log(chestr);
	if(chestr == "none")
	{
	   document.getElementById("p_endtime").style.display="block";
	   $("#enddate").attr('disabled' ,false);
	   //$("input:checkbox[value='1']").attr('checked','true');
	}
	else
	{
	  document.getElementById("p_endtime").style.display="none";
	  $("#enddate").attr('disabled' ,true);
	  //$("input:checkbox[value='0']").attr('checked','false');
	}
}

layui.use(['colorpicker','laydate','layer','form' ,'jquery'], function() {
	var layer = layui.layer, $ = layui.jquery ,form = layui.form;
	var laydate =layui.laydate;
	//var xmSelect =layui.xmSelect;
	var sharers = sharer.getValue('nameStr');
	//console.log(sharers)

    var colorpicker = layui.colorpicker;
	  //渲染
	  colorpicker.render({
		elem: '#mycolor'  //绑定元素
		,color: '#2ec770' //设置默认色
		,done: function(color){
		  $('#color').val(color); //向隐藏域赋值
		  //layer.tips('给指定隐藏域设置了颜色值：'+ color, this.elem);
		  color || this.change(color); //清空时执行 change
		}
		
		
	  });
	  
		//日期时间选择器
	  laydate.render({
		elem: '#startdate'
		,type: 'datetime'
		,zIndex: 99999999
	  });
		//日期时间选择器
	  laydate.render({
		elem: '#enddate'
		,type: 'datetime'
		,zIndex: 99999999
	  });
	  
		form.on('checkbox(filter)', function(data){
		  console.log(data.elem); //得到checkbox原始DOM对象
		  console.log(data.elem.checked); //是否被选中，true或者false
		  console.log(data.value); //复选框value值，也可以通过data.elem.value得到
		  console.log(data.othis); //得到美化后的DOM对象
		});  
		
		form.render();


		$("#submit").click(function(){
		    var users =sharer.getValue('nameStr');
			if($('#isend').is(':checked')) {
				var isend = $("#isend").val();
				console.log(isend);
			}
		});

		//监听提交
	    form.on('submit(demo1)', function(data){
			
			//layer.alert(JSON.stringify(data.field), {
			//  title: '最终的提交信息'
			//})
			
			var color = $("#color").val();
			var event = $("#event").val();
			var startdate = $("#startdate").val();
			var enddate = $("#enddate").val();
			if($('#isend').is(':checked')) {
				var isend = $("#isend").val();
			}else{
				var isend = 0;
			}
			
			//console.log(sharers);
			var users =sharer.getValue('nameStr');
			
			

			$.ajax({
				type: "post",
				url: '{:url("add")}',
				data:'color='+color+'&event='+event+'&starttime='+startdate+'&endtime='+enddate+'&sharer='+users+'&isend='+isend,
				success: function (msg) {
					//console.log(msg);
					//return false;
					//parent.location.reload();
					if (msg.code == 1) {
						parent.location.reload();
					}else {
						layer.msg('出现未知错误!');
						return false;
					}
				},error: function () {
					alert("出现错误");
					return false;
				}
			}); //ajax结束
			
			return false;
	    });
		
		
	
});
</script>
{/block}




